/*
 * ControllerIdentification.java
 *
 * Created on 30. Mai 2007, 10:47
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package DieSiedler;

import java.util.Date;
import java.util.LinkedList;

/**
 *
 * @author oliver
 */
public class ControllerIdentification {
    
    /** Creates a new instance of ControllerIdentification */
    private long lifetime;
    private Date timestamp;
    private int controllerID;
    private LinkedList<Integer> myPlayers;
    public ControllerIdentification(long lifetime, int controllerID) {
        this.timestamp= new Date();
        this.lifetime = lifetime;
        this.controllerID=controllerID;
        myPlayers= new LinkedList<Integer>();
    }
    
    public boolean isAlive(){
        return (((timestamp.getTime()+lifetime))>=System.currentTimeMillis());
    }
    
    public void refreshTimestamp(){
        timestamp=new Date();
    }
    
    public boolean addPlayer(int playerID){
        if(!myPlayers.contains(playerID)){
            return myPlayers.add(playerID);
        }
        return false;
    }
    
    public boolean removePlayer(int playerID){
        return myPlayers.remove(new Integer(playerID));
    }
    
    public LinkedList getPlayerIDs(){
        return myPlayers;
    }
            
    public int getControllerID(){
        return controllerID;
    }
    
   
    
    
    
}
